//
//  CompositeShape.h
//  Ray Tracer
//
//  Created by Kaila, Ashish on 4/7/13.
//  Copyright (c) 2013 Kaila, Ashish. All rights reserved.
//

#ifndef __Ray_Tracer__CompositeShape__
#define __Ray_Tracer__CompositeShape__

#include "scene_object.h"
#include <vector>

class CompositeShape : public SceneObject
{
public:
    CompositeShape();
    
    // Adds child shape to composite shape
    void addChildShape(const SceneObject* childShape);
    
    // Returns true if an intersection occured, false otherwise.
    bool intersect(Ray3D& ray, const Matrix4x4& worldToModel, const Matrix4x4& modelToWorld) const;
    
    // Returns true if world point is contained within the object
    virtual bool contains(const Point3D& worldPoint, const Matrix4x4& worldToModel) const;
    
protected:
    
    // Performs intersection with a specified child object
    bool intersectWithChildShape(Ray3D& ray,
                                 unsigned int childIndex,
                                 const Matrix4x4& worldToModel,
                                 const Matrix4x4& modelToWorld) const;
    
    // Determines whether a world point is contained in shape
    bool pointContainedInChildShape(const Point3D& worldPoint, const Matrix4x4& worldToModel, unsigned int index) const;
    
protected:
    std::vector<const SceneObject*> _childShapes;
};

#endif /* defined(__Ray_Tracer__CompositeShape__) */
